// pages/supplier/supplier.js
import { areaList } from '~/miniprogram_npm/@vant/area-data/index';
import baseteam from '~/utils/teamleader.js'
import basesup from '~/utils/supplier.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        fenlei: [],
        tabsactive: "全部",
        area: false,
        areaList,
        changeareadata: [],

        synthesis: 0,
        collect:0,
        browse:0,

        "page": "1",
        "pageSize": "10",
        companylist:[],
    },
    onclone() {
        this.setData({
            area: false
        })
    },
    openarea() {
        this.setData({
            area: true
        })
        this.getcompanylist()

    },
    areafirm(item) {
        this.setData({
            changeareadata: item.detail.values,
        });
        this.onclone()
        this.getcompanylist()

    },
    tabsonChange(items) {
        console.log(items)
        this.setData({
            tabsactive: items.detail.name
        })
        this.getcompanylist()
    },
    async getfenlei() {
        let resdata = await baseteam.zhuyinglist()
        this.setData({
            fenlei: resdata.data.result
        })
        this.selectComponent('#vatber').resize();
    },
    chongzhi() {
        this.setData({
            synthesis: 0,
            "page": "1",
            collect:0,
        })
    },
    bindonclone(){
        this.setData({
            changeareadata:[]
        })
        this.onclone()
    },
    async onclikzong() {
        if (this.data.synthesis == 0) {
            this.chongzhi()
            this.setData({
                synthesis: 1
            })
            this.getcompanylist()

        } else {
            this.chongzhi()
            this.setData({
                synthesis: 0
            })
        }
    },
    collstart(){
        if (this.data.collect == 0) {
            this.chongzhi()
            this.setData({
                collect: 1
            })
            this.getcompanylist()

        } else if(this.data.collect == 1) {
            this.chongzhi()
            this.setData({
                collect: 2
            })
            this.getcompanylist()

        }else{
            this.chongzhi()
            this.setData({
                collect: 0
            })
        }
    },
    browsestart(){
        if (this.data.browse == 0) {
            this.chongzhi()
            this.setData({
                browse: 1
            })
            this.getcompanylist()

        } else if(this.data.browse == 1) {
            this.chongzhi()
            this.setData({
                browse: 2
            })
            this.getcompanylist()

        }else{
            this.chongzhi()
            this.setData({
                browse: 0
            })
        }
    },
    async getcompanylist() {
        let reqdata = {
            "page": this.data.page,
            "pageSize": this.data.pageSize,
            "storeName": "",
            "categoryName": this.data.tabsactive,
            "synthesis": this.data.synthesis,
            "collect": this.data.collect,
            "browse": this.data.browse,
            "area": ""
        }
        if (this.data.changeareadata.length != 0 &&this.data.changeareadata[0].name != '' && this.data.changeareadata[0].name != undefined && this.data.changeareadata[0].name != null) {
            reqdata.area = this.data.changeareadata[0].name
        }
        let resdata = await basesup.companylist(reqdata)
        // console.log("resdata6666",resdata);
        if (resdata.code == 200) {
            this.setData({
                companylist: resdata.data.data.items.records
            })
            console.log('companylist',this.data.companylist);
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getfenlei()
        this.getcompanylist()
    },
    navecompany(items) {
        console.log(items)
        wx.navigateTo({
            url: '../supplier_information/supplier_information?id='+items.currentTarget.dataset.select,
        })
    },
    suppliersearch() {
        wx.navigateTo({
            url: '../supplier_search/supplier_search',
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})